<html>
<title></title>
<body>
<center>
<h1>Problem H</h1>
<h1>Silly Sort</h1>
</center>

<h2>Problem</h2>
<p>Your younger brother has an assignment and needs some help. His teacher gave him a sequence of numbers to be sorted in ascending order. During the sorting process, the places of two numbers can be interchanged. Each interchange has a cost, which is the sum of the two numbers involved.
<p>You must write a program that determines the minimal cost to sort the sequence of numbers.

<h2>Input</h2>
<p>The input file contains several test cases. Each test case consists of two lines. The first line contains a single integer n (n >1), representing the number of items to be sorted. The second line contains n different integers (each positive and less than 1000), which are the numbers to be sorted.
<p>The input is terminated by a zero on a line by itself.

<h2>Output</h2>
<p>For each test case, the output is a single line containing the test case number and the minimal cost of sorting the numbers in the test case.
<p>Place a blank line after the output of each test case

<h2>Sample Input</h2>
<pre>
3
3 2 1
4
8 1 2 4
5
1 8 9 7 6
6
8 4 5 3 2 7
0
</pre>
<h2>Output for the Sample Input</h2>
<pre>
Case 1: 4

Case 2: 17

Case 3: 41

Case 4: 34
</pre>
<hr>
<b>Problem Source: </b>ACM/ICPC World Finals 2002. Problem H. Silly Sort<br>
<b>Problem Archive: </b>None<br>
</body>
</html>